<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class CheckRole extends CI_Controller {
	function __construct() {
		parent::__construct ();
		$this->load->helper('url');
	}
	function check()
	{
	//Check quyen o day: Neu nhu dang nhap voi quyen admin thi
	   if(!$this-> is_logined($this->session->userdata('sessionUserAdmin')))
		{
			$this->session->sess_destroy();
			$responce->ret='logout';
			$responce->secure=rand(1, 1000000);
			$responce->checkCode=rand(1, 1000000);  
			echo json_encode($responce);
			die();
		}else
		{
			$responce->ret=rand(1, 1000000);
			$responce->secure=rand(1, 1000000);
			$responce->checkCode=rand(1, 1000000);  
			echo json_encode($responce);
		}
	}
	private function is_logined($user, $group='', $type = 'admin')
	{
		switch(strtolower($type))
		{
			case 'admin':
			    if($user && trim($user) != '' && $user ='thang' )
			    {
					return true;
			    }
			    break;
			case 'home':
			    if($user && trim($user) != '' && (int)$user > 0 && $group && trim($group) != '' && (int)$group > 0 && (int)$group < 4)
			    {
					return true;
			    }
			    break;
		}
		return false;
	}
	
}

